package com.lm.activiti.boot.cases;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.common.collect.Lists;
import com.lm.activiti.boot.cases.dto.CProperties;
import com.lm.activiti.boot.cases.dto.ParentProperties;
import org.dozer.DozerBeanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author lm_jcf
 * @date 2018/10/22 18:12
 */
@RestController
public class TestPropertiesService {

    public static final Logger LOG = LoggerFactory.getLogger(TestPropertiesService.class);

    @Value("${spr.limt:10}")
    private Integer sum;

    @Value("#{'${album.ip}'.split(',')}")
    private List<String> list = Lists.newLinkedList();

    @Value("${spr.limt}")
    private String str;

    @RequestMapping("/test_sum")
    public void setSum(@RequestParam Integer sum) {
        this.sum = sum;
        LOG.info("测试注入：" + sum);
        LOG.info("测试注入list:{}", JSON.toJSONString(list));

        LOG.info("类的名：{}", this.hashCode());

        try {
            Thread.sleep(60 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        LOG.info("测试注入list:{}", str);

        Date verifier = null;
        inPeriod(null, null, verifier);
    }

    private boolean inPeriod(@NotNull Date start, @NotNull Date end, @NotNull Date verifier) {

//        return start.getTime() <= verifier.getTime() && verifier.getTime() <= end.getTime();
        return false;
    }

    @RequestMapping(value = "/test_properties",method = RequestMethod.POST)
    public String testParentPour(@RequestBody  ParentProperties parentProperties) {
        String json = JSON.toJSONString(parentProperties);
        LOG.info(json);

        CProperties cProperties = new CProperties();
        DozerBeanMapper beanMapper = new DozerBeanMapper();
        beanMapper.map(parentProperties.getT(), cProperties);

        Object object = parentProperties.getObject();

        System.out.println(object);
        JSONArray objects = JSON.parseArray(JSON.toJSONString(parentProperties.getObject()));
        List<CProperties> list1 = objects.toJavaList(CProperties.class);
        System.out.println("转换后"+list1);

        List<CProperties> list2 = JSON.parseArray(JSON.toJSONString(parentProperties.getObject()), CProperties.class);

        System.out.println("第二种转换："+list2);

        return json;
    }

    public static void main(String[] args) {

        List<Integer> list = Lists.newArrayList();
//        list.add(1);
        List<Integer> list2 = Lists.newArrayList();
        list2.add(1);
        list2.add(12);

        list.retainAll(list2);

        System.out.println(list.size());
    }


    public void createHtmlPdf() {

    }
}
